package cn.usts.edu.lesson07;

import java.util.concurrent.CopyOnWriteArrayList;

/**
 * 测试jdk内置的安全集合
 * */

public class CopyOnWriteArrayListDemo {
    public static void main(String[] args) {
        CopyOnWriteArrayList<String> list = new CopyOnWriteArrayList<>();
        for (int i = 0; i < 10000; i++) {
            new Thread(()->{
                list.add(Thread.currentThread().getName()   );
            }).start();
        }

        try {
            Thread.sleep(1000); // 等待线程结束
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println(list.size());// 打印list长度
    }
}
